home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo2.zoo / demo / ex / ex_set.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-31  |  4.9 KB  |  238 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. static char *sccsid = "@(#)ex_set.c    7.5 (Berkeley) 3/9/87; 1.2 (Bellcore)    87/04/24";
  9. #endif not lint
  10.  
  11. #include "ex.h"
  12. #include "ex_temp.h"
  13. #include "ex_tty.h"
  14.  
  15. /*
  16.  * Set command.
  17.  */
  18. char    optname[ONMSZ];
  19.  
  20. set()
  21. {
  22.     register char *cp;
  23.     register struct option *op;
  24.     register int c;
  25.     bool no;
  26.     extern short ospeed;
  27.  
  28.     setnoaddr();
  29.     if (skipend()) {
  30.         if (peekchar() != EOF)
  31.             ignchar();
  32.         propts();
  33.         return;
  34.     }
  35.     do {
  36.         cp = optname;
  37.         do {
  38.             if (cp < &optname[ONMSZ - 2])
  39.                 *cp++ = ex_getchar();
  40.         } while (isalnum(peekchar()));
  41.         *cp = 0;
  42.         cp = optname;
  43.         if (eq("all", cp)) {
  44.             if (inopen)
  45.                 pofix();
  46.             prall();
  47.             goto next;
  48.         }
  49.         no = 0;
  50.         if (cp[0] == 'n' && cp[1] == 'o') {
  51.             cp += 2;
  52.             no++;
  53.         }
  54.         /* Implement w300, w1200, and w9600 specially */
  55.         if (eq(cp, "w300")) {
  56.             if (ospeed >= B1200) {
  57. dontset:
  58.                 ignore(ex_getchar());    /* = */
  59.                 ignore(getnum());    /* value */
  60.                 continue;
  61.             }
  62.             cp = "window";
  63.         } else if (eq(cp, "w1200")) {
  64.             if (ospeed < B1200 || ospeed >= B2400)
  65.                 goto dontset;
  66.             cp = "window";
  67.         } else if (eq(cp, "w9600")) {
  68.             if (ospeed < B2400)
  69.                 goto dontset;
  70.             cp = "window";
  71.         }
  72.         for (op = options; op < &options[NOPTS]; op++)
  73.             if (eq(op->oname, cp) || op->oabbrev && eq(op->oabbrev, cp))
  74.                 break;
  75.         if (op->oname == 0)
  76.             serror("%s: No such option@- 'set all' gives all option values", cp);
  77.         c = skipwh();
  78.         if (peekchar() == '?') {
  79.             ignchar();
  80. printone:
  81.             propt(op);
  82.             noonl();
  83.             goto next;
  84.         }
  85.         if (op->otype == ONOFF) {
  86.             op->ovalue = 1 - no;
  87.             if (op == &options[PROMPT])
  88.                 oprompt = 1 - no;
  89.             goto next;
  90.         }
  91.         if (no)
  92.             serror("Option %s is not a toggle", op->oname);
  93.         if (c != 0 || setend())
  94.             goto printone;
  95.         if (ex_getchar() != '=')
  96.             serror("Missing =@in assignment to option %s", op->oname);
  97.         switch (op->otype) {
  98.  
  99.         case NUMERIC:
  100.             if (!isdigit(peekchar()))
  101.                 error("Digits required@after =");
  102.             op->ovalue = getnum();
  103.             if (value(TABSTOP) <= 0)
  104.                 value(TABSTOP) = TABS;
  105.             if (value(HARDTABS) <= 0)
  106.                 value(HARDTABS) = TABS;
  107.             if (op == &options[WINDOW]) {
  108.                 if (value(WINDOW) >= LINES)
  109.                     value(WINDOW) = LINES-1;
  110.                 vsetsiz(value(WINDOW));
  111.             }
  112.             if (strcmp(op->oname,"font")==0)
  113.                 winch();
  114.             break;
  115.  
  116.         case STRING:
  117.         case OTERM:
  118.             cp = optname;
  119.             while (!setend()) {
  120.                 if (cp >= &optname[ONMSZ])
  121.                     error("String too long@in option assignment");
  122.                 /* adb change:  allow whitepace in strings */
  123.                 if( (*cp = ex_getchar()) == '\\')
  124.                     if( peekchar() != EOF)
  125.                         *cp = ex_getchar();
  126.                 cp++;
  127.             }
  128.             *cp = 0;
  129.             if (op->otype == OTERM) {
  130. /*
  131.  * At first glance it seems like we shouldn't care if the terminal type
  132.  * is changed inside visual mode, as long as we assume the screen is
  133.  * a mess and redraw it. However, it's a much harder problem than that.
  134.  * If you happen to change from 1 crt to another that both have the same
  135.  * size screen, it's OK. But if the screen size if different, the stuff
  136.  * that gets initialized in vop() will be wrong. This could be overcome
  137.  * by redoing the initialization, e.g. making the first 90% of vop into
  138.  * a subroutine. However, the most useful case is where you forgot to do
  139.  * a setenv before you went into the editor and it thinks you're on a dumb
  140.  * terminal. Ex treats this like hardcopy and goes into HARDOPEN mode.
  141.  * This loses because the first part of vop calls oop in this case.
  142.  * The problem is so hard I gave up. I'm not saying it can't be done,
  143.  * but I am saying it probably isn't worth the effort.
  144.  */
  145.                 if (inopen)
  146. error("Can't change type of terminal from within open/visual");
  147.                 setterm(optname);
  148.             } else {
  149.                 CP(op->osvalue, optname);
  150.                 op->odefault = 1;
  151.             }
  152.             break;
  153.         }
  154. next:
  155.         flush();
  156.     } while (!skipend());
  157.     eol();
  158. }
  159.  
  160. setend()
  161. {
  162.  
  163.     return (iswhite(peekchar()) || endcmd(peekchar()));
  164. }
  165.  
  166. prall()
  167. {
  168.     register int incr = (NOPTS + 2) / 3;
  169.     register int rows = incr;
  170.     register struct option *op = options;
  171.  
  172.     for (; rows; rows--, op++) {
  173.         propt(op);
  174.         tab(24);
  175.         propt(&op[incr]);
  176.         if (&op[2*incr] < &options[NOPTS]) {
  177.             tab(56);
  178.             propt(&op[2 * incr]);
  179.         }
  180.         putNFL();
  181.     }
  182. }
  183.  
  184. propts()
  185. {
  186.     register struct option *op;
  187.  
  188.     for (op = options; op < &options[NOPTS]; op++) {
  189. #ifdef V6
  190.         if (op == &options[TERM])
  191. #else
  192.         if (op == &options[TTYTYPE])
  193. #endif
  194.             continue;
  195.         switch (op->otype) {
  196.  
  197.         case ONOFF:
  198.         case NUMERIC:
  199.             if (op->ovalue == op->odefault)
  200.                 continue;
  201.             break;
  202.  
  203.         case STRING:
  204.             if (op->odefault == 0)
  205.                 continue;
  206.             break;
  207.         }
  208.         propt(op);
  209.         ex_putchar(' ');
  210.     }
  211.     noonl();
  212.     flush();
  213. }
  214.  
  215. propt(op)
  216.     register struct option *op;
  217. {
  218.     register char *name;
  219.     
  220.     name = op->oname;
  221.  
  222.     switch (op->otype) {
  223.  
  224.     case ONOFF:
  225.         ex_printf("%s%s", op->ovalue ? "" : "no", name);
  226.         break;
  227.  
  228.     case NUMERIC:
  229.         ex_printf("%s=%d", name, op->ovalue);
  230.         break;
  231.  
  232.     case STRING:
  233.     case OTERM:
  234.         ex_printf("%s=%s", name, op->osvalue);
  235.         break;
  236.     }
  237. }
  238.